package com.hqj.client.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hqj.client.entity.BlogsTables;
import com.hqj.client.mapper.BlogsTableMapper;
import com.hqj.client.service.BlogsTableService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 王建林
 * @version 1.0
 * @date 2020/10/12
 */
@Service
public class BlogsTableServiceImpl implements BlogsTableService {
    @Resource
    private BlogsTableMapper blogsTableMapper;

    /**
     * 分页查询
     *
     * @param page
     * @param size
     * @return java.util.List<com.hqj.client.entity.BlogsTable>
     * @date 2020/10/13 16:33
     */
    @Override
    public List<BlogsTables> findPage(int page, int size) {
        IPage<BlogsTables> iPage = blogsTableMapper.selectPage(new Page<>(page, size), null);
        return iPage.getRecords();
    }

    /**
     * 删除
     *
     * @param id
     * @return java.lang.String
     * @date 2020/10/13 16:34
     */
    @Override
    public int delete(Long id) {
        QueryWrapper<BlogsTables> wrapper = new QueryWrapper<>();
        wrapper.eq("id", id);
        BlogsTables selectOne = blogsTableMapper.selectOne(wrapper);
        selectOne.setIsDetele(1);

        return blogsTableMapper.updateById(selectOne);
    }

    /**
     * 修改
     * @param blogsTable
     * @return void
     * @date 2020/10/13 16:39
     */
    @Override
    public int update(BlogsTables blogsTable) {
        return blogsTableMapper.updateById(blogsTable);
    }

    /**
     * 增加
     *
     * @param blogsTable
     * @return java.lang.String
     * @date 2020/10/13 16:56
     */
    @Override
    public int add(BlogsTables blogsTable) {

        return blogsTableMapper.insert(blogsTable);
    }

    /**
     * 查询全部
     *
     * @param
     * @return java.util.List<com.hqj.client.entity.BlogsTables>
     * @date 2020/10/13 22:47
     */
    @Override
    public List<BlogsTables> findAll() {

        return blogsTableMapper.selectList(null);
    }


    /**
     * 根据id查询
     *
     * @param id
     * @return com.hqj.client.entity.BlogsTables
     * @date 2020/10/13 22:47
     */
    @Override
    public BlogsTables selectOne(Long id) {
        QueryWrapper<BlogsTables> wrapper = new QueryWrapper<>();
        wrapper.eq("id", id);
        BlogsTables blogsTables = blogsTableMapper.selectOne(wrapper);
        return blogsTables;
    }
}
